//
//  NXANonIssueViewController.m
//  NXA-MasterDrivingSkills
//
//  Created by jps on 2017/1/5.
//  Copyright © 2017年 NXA. All rights reserved.
//

#import "NXANonIssueViewController.h"
#import "global.h"
#import "BGHomePageTopGoodsCell.h"
#import "BGTopSilderBar.h"
#import "NXANonIssueModel.h"


static NSString* ALCELLID = @"BGHomePageTopGoodsCell";


@interface NXANonIssueViewController ()<UICollectionViewDataSource,UICollectionViewDelegate>

@property(nonatomic,weak)BGTopSilderBar* silderBar;
@property(nonatomic,weak)UICollectionView* collectView;
@property(nonatomic,assign)int currentBarIndex;

@property(nonatomic,strong)NSMutableArray *sliderItemArr;    //!<顶部滑动天数的数据源
//@property(nonatomic,strong)NXASingleDataManager *dataManager;    //!<

@end

@implementation NXANonIssueViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self initComponents];
    
    //获取未公布班表日期 成功后初始化滑动联动控件
//    [self fetchNonIssueDateWithResId:self.dataManager.loginModel.ResId areaUrl:self.dataManager.loginModel.serverUrl];
    
    //获取未公布班表
    //[self fetchTimeSegmentWithCoachId:self.dataManager.loginModel.ResId date:@"2017-01-22" areaUrl:self.dataManager.loginModel.serverUrl];
    
   
}



#pragma mark - 初始化

- (void)initComponents
{
    self.navigationController.automaticallyAdjustsScrollViewInsets = NO;
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.navigationItem.title = @"未公布班表";
    UIImage *backImage = [UIImage imageNamed:@"back"];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:backImage style:UIBarButtonItemStyleDone target:self action:@selector(backAction:)];
    
}

- (void)backAction:(UIBarButtonItem *)barItem
{
    [self.navigationController popViewControllerAnimated:YES];
}



#pragma mark - 滑动联动

/**
 初始化BGTopSilderBar
 */
-(void)initSilderBar{
    BGTopSilderBar* silder = [[BGTopSilderBar alloc] initWithFrame:CGRectMake(0,0,screenW, 50)];
    silder.items = self.sliderItemArr;
    silder.contentCollectionView = _collectView;//_collectView必须要在前面初始化,不然这里值为nil
    _silderBar = silder;
    [self.view addSubview:silder];
}
/**
 初始化底部滑动的collectionView
 */
-(void)initCollectView{
    CGFloat Margin = 0;
    CGFloat W = screenW;
    CGFloat H = screenH-75;
    CGRect rect = CGRectMake(Margin,50, W,H);
    //初始化布局类(UICollectionViewLayout的子类)
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
    layout.itemSize = CGSizeMake(W, H);
    layout.minimumInteritemSpacing = 0;//设置行间隔
    layout.minimumLineSpacing = 0;//设置列间隔
    //初始化collectionView
    UICollectionView* collectView = [[UICollectionView alloc]initWithFrame:rect collectionViewLayout:layout];
    collectView.tag = 0;
    collectView.backgroundColor = [UIColor clearColor];
    _collectView = collectView;
    //设置代理
    collectView.delegate = self;
    collectView.dataSource = self;
    collectView.showsHorizontalScrollIndicator = NO;
    // 注册cell
    [collectView registerNib:[UINib nibWithNibName:ALCELLID bundle:nil] forCellWithReuseIdentifier:ALCELLID];
    //设置水平方向滑动
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    //设置分页
    collectView.pagingEnabled = YES;
    [self.view addSubview:collectView];
}

#pragma -- UICollectionViewDataSource

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.sliderItemArr.count;//此处页面的张数要跟顶部滑动栏的item个数一样
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    BGHomePageTopGoodsCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:ALCELLID forIndexPath:indexPath];
    cell.backgroundColor = color(rand()%255,rand()%255,rand()%255,1.0);
    
    cell.date = self.sliderItemArr[indexPath.item];
    
    return cell;
}





#pragma mark - 网络请求

/**
 获取未公布班表日期(访问地市)
 
 @param resId 教练编号
 */
- (void)fetchNonIssueDateWithResId:(NSString *)resId areaUrl:(NSString *)areaUrl
{
//    NXANetworkingDataManager *netManager = [NXANetworkingDataManager shareManager];
//    NSString *urlString = [areaUrl stringByAppendingString:@"app/GetDataInfo"];
//    
//    NSDictionary *tempDic = @{@"ResId":resId,
//                              @"PlatformType":@"IOS",
//                              @"RoleType":@"c",
//                              @"PhoneMode":kPhoneMode};
//    NSString *jsonStr = [NSDictionary dictionaryToJson:tempDic];
//    NSDictionary *parameDic = @{@"CommandCode":@"GetScheduleDate14",
//                                @"Marker":@(1483514647244),
//                                @"TransferData":jsonStr};
//    NSDictionary *parameDic2 = @{@"entity":parameDic};
//    
//    [netManager postDataWithUrl:urlString parameters:parameDic2 success:^(id json) {
//        
//        
//        NSDictionary *resultDic = (NSDictionary *)json;
//        //NSString *code = resultDic[@"ErrorCode"];
//        DLog(@"%s",object_getClassName(resultDic[@"ResultInfo"]));
//        NSArray *arr = (NSArray *)[NXAPublicClass getDicString:resultDic[@"ResultInfo"]];
//        DLog(@"%@",arr);
//        [arr enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
//            [self.sliderItemArr addObject:obj[@"Reservation_date"]];
//        }];
//
//        
//        //==============  请求到数据，初始化控件  ==============
//        
//        [self initCollectView];//初始化底部滑动的collectionView
//        [self initSilderBar];//初始化顶部BGTopSilderBar
//        
//        
//    } failure:^(NSError *error) {
//        
//    }];
}












#pragma mark - 懒加载

//- (NXASingleDataManager *)dataManager
//{
//    if (!_dataManager) {
//        _dataManager = [NXASingleDataManager shareManager];
//    }
//    return _dataManager;
//}

- (NSMutableArray *)sliderItemArr
{
    if (_sliderItemArr == nil) {
        _sliderItemArr = [[NSMutableArray alloc]init];
    }
    return _sliderItemArr;
}




@end
